package com.example.fw;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;

public class HelperWithWebDriverBase {
	
	protected ApplicationManager manager;
	private WebDriver driver;
	
	public HelperWithWebDriverBase (ApplicationManager manager){
		this.manager = manager;
		driver = manager.getWebDriverHelper().getDriver(); 
	}
	
	protected void type(String text, String locator) {
		driver.findElement(By.name(locator)).clear();
		driver.findElement(By.name(locator)).sendKeys(text);
	}
	
	protected void selectCurrentField(String selectBdayValue, By locator) {
		new Select(findElement(locator)).selectByVisibleText(selectBdayValue);
	}
		
	protected  boolean isElementPresent(By by) {
		try {
			driver.findElement(by);
			return true;
		} catch (NoSuchElementException e) {
			return false;
		}
	}
	
	protected WebElement findElement(By locator) {
		return driver.findElement(locator);
	}
	
	protected List<WebElement> findElements(By locator) {
		return driver.findElements(locator);
	}

	protected void openUrl(String url) {
		driver.get(url);
	}

	protected WebElement click(By locator) {
		findElement(locator).click();
		return null;
	}
		
}

